# 微信公众号一键排版工具 - 自动安装脚本 (Windows PowerShell)

Write-Host "======================================" -ForegroundColor Cyan
Write-Host "  微信公众号一键排版工具 - 安装向导" -ForegroundColor Cyan
Write-Host "======================================" -ForegroundColor Cyan
Write-Host ""

# 检查Node.js
Write-Host "1. 检查Node.js..." -ForegroundColor Yellow
try {
    $nodeVersion = node --version
    Write-Host "   ✓ Node.js版本: $nodeVersion" -ForegroundColor Green
} catch {
    Write-Host "   ✗ 未安装Node.js，请先安装 Node.js 18+" -ForegroundColor Red
    Write-Host "   下载地址: https://nodejs.org/" -ForegroundColor Yellow
    exit 1
}

# 安装后端依赖
Write-Host ""
Write-Host "2. 安装后端依赖..." -ForegroundColor Yellow
Set-Location backend
npm install
if ($LASTEXITCODE -ne 0) {
    Write-Host "   ✗ 后端依赖安装失败" -ForegroundColor Red
    exit 1
}
Write-Host "   ✓ 后端依赖安装完成" -ForegroundColor Green

# 安装前端依赖
Write-Host ""
Write-Host "3. 安装前端依赖..." -ForegroundColor Yellow
Set-Location ../frontend
npm install
if ($LASTEXITCODE -ne 0) {
    Write-Host "   ✗ 前端依赖安装失败" -ForegroundColor Red
    exit 1
}
Write-Host "   ✓ 前端依赖安装完成" -ForegroundColor Green

# 创建上传目录
Write-Host ""
Write-Host "4. 创建上传目录..." -ForegroundColor Yellow
Set-Location ../backend
if (-not (Test-Path "uploads")) {
    New-Item -ItemType Directory -Path "uploads" | Out-Null
    Write-Host "   ✓ 上传目录创建完成" -ForegroundColor Green
} else {
    Write-Host "   ✓ 上传目录已存在" -ForegroundColor Green
}

# 检查环境变量文件
Write-Host ""
Write-Host "5. 检查环境配置..." -ForegroundColor Yellow
if (-not (Test-Path ".env")) {
    Write-Host "   ! 未找到.env文件" -ForegroundColor Yellow
    Write-Host "   请手动创建 backend/.env 文件，参考环境配置说明.md" -ForegroundColor Yellow
} else {
    Write-Host "   ✓ 环境配置文件存在" -ForegroundColor Green
}

# 返回项目根目录
Set-Location ..

Write-Host ""
Write-Host "======================================" -ForegroundColor Cyan
Write-Host "  安装完成！" -ForegroundColor Green
Write-Host "======================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "下一步:" -ForegroundColor Yellow
Write-Host "  1. 配置环境变量（backend/.env）" -ForegroundColor White
Write-Host "  2. 初始化数据库（运行 database/schema.sql）" -ForegroundColor White
Write-Host "  3. 启动后端：cd backend && node src/app.js" -ForegroundColor White
Write-Host "  4. 启动前端：cd frontend && npm run dev" -ForegroundColor White
Write-Host ""
Write-Host "详细说明请查看：README.md" -ForegroundColor Cyan
Write-Host ""

